﻿/*
报错解决办法，不编译此段代码，操作如下
Edit > Project Settings > Player，然后在Other Settings部分的Scripting Define Symbols中**移除**"SPINE_PACKAGE"即可
要代码生效，编译此段代码，操作如下
Edit > Project Settings > Player，然后在Other Settings部分的Scripting Define Symbols中**添加**"SPINE_PACKAGE"即可
 */
#if SPINE_PACKAGE
using Spine;
using Spine.Unity;
using System.Collections.Generic;

namespace Super
{
	public static class SpineUtil
	{
		/// <summary>
		/// 修改附件图片
		/// </summary>
		/// <param name="skeletonRenderer"></param>
		/// <param name="slotName">插槽名称</param>
		/// <param name="attachmentName">附件图片路径名称</param>
		public static void ChangeAttachment(SkeletonRenderer skeletonRenderer, string slotName, string attachmentName)
		{
			var attachment = skeletonRenderer.skeleton.GetAttachment(slotName, attachmentName);
			skeletonRenderer.skeleton.FindSlot(slotName).Attachment = attachment;
		}

		/// <summary>
		/// 改变插槽的部件为对应皮肤中的插槽部件
		/// </summary>
		/// <param name="slotName"></param>
		/// <param name="skinName"></param>
		public static void ChangeSlotWithSkin(SkeletonRenderer skeletonRenderer, string slotName, string skinName)
		{
			SkeletonData skeletonData = skeletonRenderer.SkeletonDataAsset.GetSkeletonData(false);
			Skin skin = skeletonData.FindSkin(skinName);
			int slotIndex = skeletonData.FindSlotIndex(slotName);
			Attachment targetAttachment = skin.GetAttachment(slotIndex, slotName);

			ChangeAttachment(skeletonRenderer, slotName, targetAttachment.Name);
		}
	}
}

#endif
